import { Component, OnInit } from '@angular/core';
import {StudentService} from "../student.service";

@Component({
  selector: 'app-student-echart-demo',
  templateUrl: './student-echart-demo.component.html',
  styleUrls: ['./student-echart-demo.component.css']
})
export class StudentEchartDemoComponent implements OnInit {
  option = null;
  constructor(private studentService:StudentService) { }
  ngOnInit() {
    this.tongji()
  }
  /*图表显示*/
  tongji(){
    this.studentService.sex().subscribe(tg=>{
      var ldata:string[] = [];
      var sdata = [];
      tg.forEach((v,i,a)=>{
        ldata.push(v.title);
        sdata.push({value:v.count,name:v.title})
      });
      this.option = {
        title : {
          text: '学院性别比例',
          subtext: '纯属虚构',
          x:'center'
        },
        tooltip : {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          data: ldata
        },
        series : [
          {
            name: '性别比例',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:sdata,
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
      /*this.option.legend.data=ldata;
      this.option.series[0].data=sdata*/
    })
  }
}
